package com.gable.exhibition.controller;

import com.alibaba.fastjson.JSON;
import com.gable.common.util.ReturnResultUtil;
import com.gable.common.util.StringUtil;
import com.gable.exhibition.service.LargeScreenService;
import com.gable.exhibition.util.MessageUtil;
import com.gable.exhibition.websocket.WSClientManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Lesson on 2018/2/27.
 */
@Controller
@RequestMapping(value="largeScreen")
public class LargeScreenController {

        Logger logger = Logger.getLogger(this.getClass());

        @Autowired
        LargeScreenService largeScreenService;

        @RequestMapping(value="/initData",method = RequestMethod.POST, produces="application/json;charset=utf-8")
        @ResponseBody
        public ReturnResultUtil page(HttpServletRequest request, HttpServletResponse response){
                try{
                        ReturnResultUtil rru = largeScreenService.qeuryLargeScreenData();
                        logger.info(JSON.toJSONString(rru));
                        return  rru;
                }catch (Exception e){
                        e.printStackTrace();
                }
                return  new ReturnResultUtil(500, MessageUtil.QUERYEXCEPTION);
        }

        /**
         * 大屏根据维修设备状态查询是高危和紧急
         * @param request
         * @param response
         * @return
         */
        @RequestMapping(value="/queryRepairByRepairStatus",method = RequestMethod.POST, produces="application/json;charset=utf-8")
        @ResponseBody
        public ReturnResultUtil queryRepairByDeviceStatus(HttpServletRequest request, HttpServletResponse response){
                try{
                    if(StringUtil.isEmpty(request.getParameter("deviceStatus"))){
                        new ReturnResultUtil(500,MessageUtil.DEVICESTATUSISNULL);
                    }
                    Long deviceStatus = Long.parseLong(request.getParameter("deviceStatus"));
                    ReturnResultUtil rru = largeScreenService.queryRepairByDeviceStatus(deviceStatus);
                        logger.info(JSON.toJSONString(rru));
                        return rru;

                }catch (Exception e){
                        e.printStackTrace();
                }
                return  new ReturnResultUtil(500, MessageUtil.QUERYEXCEPTION);
        }

}
